--
-- Author: shunguo.chen
-- Date: 2019-06-04 15:42:57
--
-- LegendResetView 神器回收界面
--

local IconRender = require("app.widget.renders.IconRender")

local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.ViewBase)

ClassRef.VIEW_ROOT_RES = Res.LegendResetScene

function ClassRef:init()
    self._ui.Button_quxiao:addClickEventListener(function()
        self:closeView()
    end)
    self._ui.Button_quding:addClickEventListener(function()
        if not self._isItemOK then
            display.pushToast(L("tips_1000093"))
        else
            executeFunc(self._onOperate, "reset")
            self:closeView()
        end
    end)

    self._tipText = self._ui["Panel/Panel_content/Text_tlt_3"]

    self._gotItemRender = IconRender.create(self._ui["Panel/Panel_content/item_1"])
    self._gotItemRender:setTipEnable(true)
    self._gotItemRender:setDefaultShowNumLimit(0)

    self._costItemRender = IconRender.create(self._ui["Panel/Panel_content/item_2"])
    self._costItemRender:setTipEnable(true)
end

function ClassRef:refresh(costItem, gotItem, showTip)
    self._costItem = costItem

    self._tipText:setVisible(showTip)
    self._gotItemRender:setData(gotItem)

    self:_refreshCost(costItem)
end

function ClassRef:_refreshCost(costItem)
    local hasNum = UD:getItemAmountByTid(costItem:getId())
    self._costItemRender:setData(costItem)
    self._costItemRender:setHasAmount(hasNum)
    self._isItemOK = hasNum >= costItem:getAmount()
end

function ClassRef:reOpen()
    self:_refreshCost(self._costItem)
end

return ClassRef
